package com.gupao.rpc.protocol.spring.reference;

import com.gupao.rpc.protocol.spring.service.RpcServerProperties;
import com.gupao.rpc.protocol.spring.service.SpringRpcProviderBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.net.UnknownHostException;

@Configuration
/*@EnableConfigurationProperties({RpcClientProperties.class})*/
public class RpcClientAutoConfiguration implements EnvironmentAware {

    private Environment environment;

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

    @Bean
    public SpringRpcReferencePostProccessor springRpcProviderBean() {
        RpcClientProperties properties = new RpcClientProperties();
        properties.setHost(environment.getProperty("rpc.client.host"));
        properties.setPort(Integer.parseInt(environment.getProperty("rpc.client.port")));
        return new SpringRpcReferencePostProccessor(properties);
    }

}
